package com.example.springboottest.student.controller;


import com.example.springboottest.student.model.Student;
import com.example.springboottest.student.service.StuMogonService;
import com.example.springboottest.student.service.StuService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("stuMongo")
public class StuMongoController {
    @Autowired
    private StuMogonService stuService;

    @ApiOperation(value = "按ID查询学生")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "学生ID", required = true, dataType = "String")
    })
    @RequestMapping(value = "/getById.api", method = {RequestMethod.POST, RequestMethod.GET})
    public Student getById(@RequestParam(value = "id") String id) {
        return stuService.doFindById(id);
    }

    @ApiOperation(value = "创建学生，默认创建成绩")
    @PostMapping(value = "/create.api")
    public void create(@RequestBody Student student) {
        stuService.doCreate(student);
    }

    @ApiOperation(value = "修改学生")
    @PostMapping(value = "/update.api")
    public void update(@RequestBody Student student) {
        stuService.doUpdate(student);
    }

    @ApiOperation(value = "查询所有学生")
    @PostMapping(value = "/findAll.api")
    public List<Student> findAll() {
        return stuService.doFindALl();
    }

    @ApiOperation(value = "分页查询所有学生")
    @PostMapping(value = "/page.api")
    public Page<Student> page() {
        return stuService.doPage();
    }

    @ApiOperation(value = "按ID删除学生")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "学生ID", required = true, dataType = "String")
    })
    @RequestMapping(value = "/deleteById.api", method = {RequestMethod.POST, RequestMethod.GET})
    public void deleteById(@RequestParam(value = "id") String id) {
        stuService.doDeleteById(id);
    }
}
